Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.8K
Vistas
angular 9 library publish error "Trying to publish a package that has been compiled by Ivy"

I migrated my angular 8.x.x project to angular 9.x.x and when I try to publish my library, it fails with below error

npm ERR! @candiman/website@9.0.0 prepublishOnly: node --eval "console.error('ERROR: Trying to publish a package that has been compiled by Ivy. This is not allowed.\nPlease delete and rebuild the package, without compiling with Ivy, before attempting to publish.\n')" && exit 1

is there anything changed in the angular 9

over 4 years ago · Santiago Trujillo
8 Respuestas
Responde la pregunta

0

UPDATE ANGULAR 12

using the --configuration production option while building the library fixed my issue

ng build --configuration production

Original answer:

using --prod option while building the library fixed my issue

ng build yourLibraryName --prod
over 4 years ago · Santiago Trujillo Denunciar

0

According to official Angular docs https://angular.io/guide/ivy#opting-out-of-ivy-in-version-9

it is better to opt out from Ivy compiler to use the older View Engine when building and publishing your library by adding this line:

enableIvy: false

to angularCompilerOptions in tsconfig.json file at the root of your library as can be seen below;

enter image description here

I've tried it after updating my Angular library to Angular version 9 and this one small change worked like a charm.

over 4 years ago · Santiago Trujillo Denunciar

0

In my case none of the solutions above worked. I noticed however that in the package.json of my library in the dist folder there is an newly added script (probably added because of this):


  "scripts": {
    "prepublishOnly": "node --eval \"console.error('ERROR: Trying to publish a package that has been compiled by NGCC. This is not allowed.\\nPlease delete and rebuild the package, without compiling with NGCC, before attempting to publish.\\nNote that NGCC may have been run by importing this package into another project that is being built with Ivy enabled.\\n')\" && exit 1"
  }

SO here either remove/replace the prepublishOnly script or publish using npm publish --ignore-scripts

over 4 years ago · Santiago Trujillo Denunciar

0

Adding

"compilationMode": "partial"

to

"angularCompilerOptions": {

}

Solved my problem

over 4 years ago · Santiago Trujillo Denunciar

0

In your angular.json file, you have a build object in your library tree. Inside build, you have a configurations object, that contains a production object and probably a development object too.

Inside build object define a new property called defaultConfiguration, and set the value: production that match with the name of the production property inside configurations object.

Your angular.json file should look like this:

"architect": {
  build": {
    "builder": "@angular-devkit/build-ng-packagr:build",
    "options": {
      "tsConfig": "projects/ngx-custom-tooltip/tsconfig.lib.json",
      "project": "projects/ngx-custom-tooltip/ng-package.json"
    },
    "configurations": {
      "production": {
        "tsConfig": "projects/ngx-custom-tooltip/tsconfig.lib.prod.json"
      },
      "development": {
        "tsConfig": "projects/ngx-custom-tooltip/tsconfig.lib.json"
      }
    },
    "defaultConfiguration": "production"
  },
  ...
}

Your tsconfig.lib.prod.json should contains this object:

"angularCompilerOptions": {
  "enableIvy": false
}

Finally, yo can execute ng build your-library-name

over 4 years ago · Santiago Trujillo Denunciar

0

While building my libraries with ng build --prod and enableIvy = false in tsconfig.lib.json I was getting the same "prepublishOnly" script added to my workspace package.json as Melchia had.

The reason why seems to be related to using a private repository via publishConfig/registry in each library's package.json, as stated in https://github.com/angular/angular/issues/37973#issuecomment-656136865

When building Angular libraries for publishing, use ng build --prod, enableIvy = false in library's tsconfig.json and, if working with a private repository, npm publish --ignore-scripts

over 4 years ago · Santiago Trujillo Denunciar

0

In addition to adding the --prod flag, if you're running on a really old version, you'll also need the following update to angular.json:

    "myproject": {
      ...
      "architect": {
        "build": {
          ...
          "configurations": {
            "production": {
              "tsConfig": "projects/mypath/tsconfig.lib.prod.json"
            }
          }
        },

with the content of that file being:

{
  "extends": "./tsconfig.lib.json",
  "angularCompilerOptions": {
    "enableIvy": false
  }
}

You can check if you're on such an old version if you still have the following lines in angular.json:

            "production": {
              "project": "projects/tsmean/spinner/ng-package.prod.json"
            }
over 4 years ago · Santiago Trujillo Denunciar

0

Fix for Angular 12+ missing component style issue

On Angular 12, while using:

ng build --configuration production

indeed solved the original issue for me, it also introduced a new one: the styles of my library component where completely missing.

I've solved this other problem by replacing:

  "angularCompilerOptions": {
    "enableIvy": false
  }

with:

  "angularCompilerOptions": {
    "compilationMode": "partial"
  }

in projects/my-library/tsconfig.lib.prod.json

Source: https://angular.io/guide/creating-libraries#building-libraries-with-ivy

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda